import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_study_app/widget/my_app_bar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CaseClearAddPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _CaseClearAddPageState();
}

class _CaseClearAddPageState extends State<CaseClearAddPage> {
  int _isPublic = -1;
  String? _date;

  _selectDate() {
    DatePicker.showDatePicker(context,
        locale: LocaleType.zh,
        showTitleActions: true,
        minTime: DateTime.now(),
        theme: DatePickerTheme(doneStyle: TextStyle(color: Color(0xFF009669))),
        onConfirm: (date) {
      _date = formatDate(date, [yyyy, '-', mm, '-', dd]);
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        title: '立案清算新增',
      ),
      body: Column(
        children: [
          Container(
            height: 1.w,
            color: Color(0xFFEEEEEE),
          ),
          Expanded(
            child: Container(
              color: Colors.white,
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    SizedBox(
                      height: 25.w,
                    ),
                    Container(
                      padding: EdgeInsets.symmetric(horizontal: 12.w),
                      child: Row(
                        children: [
                          SizedBox(
                            width: 60.w,
                            child: TextField(
                              keyboardType: TextInputType.number,
                              textAlign: TextAlign.center,
                              maxLines: 1,
                              decoration: InputDecoration(
                                contentPadding:
                                    EdgeInsets.symmetric(vertical: 10.w),
                                isDense: true,
                                hintText: '2021',
                                border: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                                enabledBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                                focusedBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                              ),
                              style: TextStyle(
                                  color: Color(0xFF999999), fontSize: 14.sp),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 10.w),
                            child: Text(
                              '湘',
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          ),
                          SizedBox(
                            width: 60.w,
                            child: TextField(
                              keyboardType: TextInputType.number,
                              maxLines: 1,
                              textAlign: TextAlign.center,
                              decoration: InputDecoration(
                                contentPadding:
                                    EdgeInsets.symmetric(vertical: 10.w),
                                isDense: true,
                                hintText: '0702',
                                border: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                                enabledBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                                focusedBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                              ),
                              style: TextStyle(
                                  color: Color(0xFF999999), fontSize: 14.sp),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 10.w),
                            child: Text(
                              '民初',
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          ),
                          SizedBox(
                            width: 60.w,
                            child: TextField(
                              keyboardType: TextInputType.number,
                              textAlign: TextAlign.center,
                              maxLength: 5,
                              maxLines: 1,
                              decoration: InputDecoration(
                                counterText: '',
                                contentPadding:
                                    EdgeInsets.symmetric(vertical: 10.w),
                                isDense: true,
                                hintText: '',
                                border: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                                enabledBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                                focusedBorder: UnderlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.w, color: Color(0xFFD8D8D8))),
                              ),
                              style: TextStyle(
                                  color: Color(0xFF999999), fontSize: 14.sp),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 10.w),
                            child: Text(
                              '号',
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          ),
                        ],
                      ),
                    ),

                    Container(
                      margin: EdgeInsets.only(top: 20.w),
                      padding: EdgeInsets.symmetric(
                          horizontal: 12.w, vertical: 10.w),
                      child: Row(
                        children: [
                          Text(
                            '合同编号（选填）',
                            style: TextStyle(
                                fontSize: 14.sp, color: Color(0xFF333333)),
                          ),
                          SizedBox(
                            width: 30.w,
                          ),
                          Expanded(
                            child: TextField(
                              textAlign: TextAlign.right,
                              maxLines: 1,
                              decoration: InputDecoration(
                                  contentPadding: EdgeInsets.zero,
                                  isDense: true,
                                  hintText: '请输入合同编号',
                                  hintStyle: TextStyle(
                                      fontSize: 14.sp,
                                      color: Color(0xFF999999)),
                                  border: InputBorder.none,
                                  enabledBorder: InputBorder.none),
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 12.w),
                      height: 1.w,
                      color: Color(0xFFEEEEEE),
                    ),
                    //借据编号
                    Container(
                      margin: EdgeInsets.only(top: 20.w),
                      padding: EdgeInsets.symmetric(
                          horizontal: 12.w, vertical: 10.w),
                      child: Row(
                        children: [
                          Text(
                            '借据编号（选填）',
                            style: TextStyle(
                                fontSize: 14.sp, color: Color(0xFF333333)),
                          ),
                          SizedBox(
                            width: 30.w,
                          ),
                          Expanded(
                            child: TextField(
                              textAlign: TextAlign.right,
                              maxLines: 1,
                              decoration: InputDecoration(
                                  contentPadding: EdgeInsets.zero,
                                  isDense: true,
                                  hintText: '请输入借据编号',
                                  hintStyle: TextStyle(
                                      fontSize: 14.sp,
                                      color: Color(0xFF999999)),
                                  border: InputBorder.none,
                                  enabledBorder: InputBorder.none),
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 12.w),
                      height: 1.w,
                      color: Color(0xFFEEEEEE),
                    ),
                    //立案时间
                    Container(
                      margin: EdgeInsets.only(top: 20.w),
                      padding: EdgeInsets.symmetric(
                          horizontal: 12.w, vertical: 10.w),
                      child: Row(
                        children: [
                          Text(
                            '立案时间',
                            style: TextStyle(
                                fontSize: 14.sp, color: Color(0xFF333333)),
                          ),
                          SizedBox(
                            width: 30.w,
                          ),
                          Expanded(
                            child: InkWell(
                              onTap: () {
                                //EasyLoading.showToast('点击时间选择');
                                _selectDate();
                              },
                              child: Text(
                                _date ?? '请选择立案时间',
                                textAlign: TextAlign.right,
                                style: TextStyle(
                                    fontSize: 14.sp,
                                    color: _date == null
                                        ? Color(0xFF999999)
                                        : Color(0xFF333333)),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 12.w),
                      height: 1.w,
                      color: Color(0xFFEEEEEE),
                    ),
                    //业务种类
                    Container(
                      margin: EdgeInsets.only(top: 20.w),
                      padding: EdgeInsets.symmetric(
                          horizontal: 12.w, vertical: 10.w),
                      child: Row(
                        children: [
                          Text(
                            '客户姓名',
                            style: TextStyle(
                                fontSize: 14.sp, color: Color(0xFF333333)),
                          ),
                          SizedBox(
                            width: 30.w,
                          ),
                          Expanded(
                            child: TextField(
                              textAlign: TextAlign.right,
                              maxLines: 1,
                              decoration: InputDecoration(
                                  contentPadding: EdgeInsets.zero,
                                  isDense: true,
                                  hintText: '请输入客户姓名',
                                  hintStyle: TextStyle(
                                      fontSize: 14.sp,
                                      color: Color(0xFF999999)),
                                  border: InputBorder.none,
                                  enabledBorder: InputBorder.none),
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 12.w),
                      height: 1.w,
                      color: Color(0xFFEEEEEE),
                    ),
                    //金额
                    Container(
                      margin: EdgeInsets.only(top: 20.w),
                      padding: EdgeInsets.symmetric(
                          horizontal: 12.w, vertical: 10.w),
                      child: Row(
                        children: [
                          Text(
                            '金额',
                            style: TextStyle(
                                fontSize: 14.sp, color: Color(0xFF333333)),
                          ),
                          SizedBox(
                            width: 30.w,
                          ),
                          Expanded(
                            child: TextField(
                              keyboardType: TextInputType.number,
                              textAlign: TextAlign.right,
                              maxLines: 1,
                              decoration: InputDecoration(
                                  contentPadding: EdgeInsets.zero,
                                  isDense: true,
                                  hintText: '请输入金额',
                                  hintStyle: TextStyle(
                                      fontSize: 14.sp,
                                      color: Color(0xFF999999)),
                                  border: InputBorder.none,
                                  enabledBorder: InputBorder.none),
                              style: TextStyle(
                                  color: Color(0xFF333333), fontSize: 14.sp),
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 12.w),
                      height: 1.w,
                      color: Color(0xFFEEEEEE),
                    ),
                    //是否公告
                    Container(
                      margin: EdgeInsets.only(top: 20.w),
                      padding: EdgeInsets.symmetric(horizontal: 12.w),
                      child: Row(
                        children: [
                          Text(
                            '是否需公告',
                            style: TextStyle(
                                fontSize: 14.sp, color: Color(0xFF333333)),
                          ),
                          InkWell(
                            onTap: () {
                              _isPublic = 1;
                              setState(() {});
                            },
                            child: Container(
                              padding: EdgeInsets.symmetric(horizontal: 20.w),
                              child: Row(
                                children: [
                                  Image.asset(
                                    _isPublic == 1
                                        ? 'assets/images/ic_single_checked.png'
                                        : 'assets/images/ic_single_check_no.png',
                                    width: 16.w,
                                    height: 16.w,
                                  ),
                                  SizedBox(
                                    width: 5.w,
                                  ),
                                  Text(
                                    '是',
                                    style: TextStyle(
                                        fontSize: 14.sp,
                                        color: Color(0xFF333333)),
                                  )
                                ],
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: () {
                              _isPublic = 0;
                              setState(() {});
                            },
                            child: Container(
                              padding: EdgeInsets.symmetric(horizontal: 20.w),
                              child: Row(
                                children: [
                                  Image.asset(
                                    _isPublic == 0
                                        ? 'assets/images/ic_single_checked.png'
                                        : 'assets/images/ic_single_check_no.png',
                                    width: 16.w,
                                    height: 16.w,
                                  ),
                                  SizedBox(
                                    width: 5.w,
                                  ),
                                  Text(
                                    '否',
                                    style: TextStyle(
                                        fontSize: 14.sp,
                                        color: Color(0xFF333333)),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          SafeArea(
            child: Container(
              padding: EdgeInsets.all(12.w),
              width: double.infinity,
              height: 74.w,
              color: Colors.white,
              child: TextButton(
                style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.all(Color(0xff009868)),
                ),
                onPressed: () {},
                child: Text(
                  '提交',
                  style: TextStyle(color: Colors.white, fontSize: 18.sp),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
